package com.ruoyi.wechat.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.wechat.common.tree.TreeNode;
import lombok.Data;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 商品标签
 * </p>
 *
 * @author YinHeng
 * @since 2024/3/26
 */
@Data
@TableName("app_product_tag")
public class ProductTag implements TreeNode<Long, ProductTag> {

    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long id;
    /**
     * 规格名称
     */
    private String name;

    private Long pId;
    /**
     * 商品ID
     */
    private Long itemId;
    /**
     * 祖籍
     */
    private String ancestors;
    /**
     * 排序
     */
    private Integer sort;

    private Integer type;

    @TableField(exist = false)
    private List<ProductTag> children;

    @Override
    public Long getPid() {
        return pId;
    }

    @Override
    public void setPid(Long pid) {
        pId = pid;
    }

    @Override
    public List<ProductTag> getChildren() {
        if (ObjectUtils.isEmpty(children)) {
            children = new ArrayList<>();
        }
        return children;
    }

    @Override
    public void setChildren(List<ProductTag> children) {
        this.children = children;
    }

    @Override
    public void addChild(ProductTag node) {
        if (ObjectUtils.isEmpty(children)) {
            children = new ArrayList<>();
        }
        children.add(node);
    }
}
